package com.dynamic.mybatis.web.tnt;

import com.dynamic.mybatis.core.utils.RandomUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.*;

@RestController
@RequestMapping("/device/")
public class DeviceController {

    @RequestMapping(path = {"crossEnvironmentPage", "page"})
    public Map<String, Object> page() {
        Map<String, Object> result = new HashMap<>();
        List<DeviceVo> deviceVoList = new ArrayList();
        for (int i = 0; i < 20; i++) {
            DeviceVo deviceVo = new DeviceVo();
            deviceVo.setCid(RandomUtils.random(1, 100) + "_" + i);
            deviceVo.setPid(RandomUtils.random(1, 100) + "_" + i);
            deviceVo.setLastOnlineTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
            deviceVo.setVirtualDeviceStatus(RandomUtils.random("starting", "started", "stopping", "stopped", "unknown"));
            deviceVo.setPlatformDeviceStatus(RandomUtils.random(1, 2, 3));
            deviceVo.setProtocol(RandomUtils.random("BRIDGE", "MQTT"));
            deviceVo.setActive("dve");
            deviceVoList.add(deviceVo);
        }
        result.put("records", deviceVoList);
        result.put("pageSize", 10);
        result.put("pageNumber", 1);
        result.put("total", 20);

        Map<String, Object> response = new HashMap<>();
        response.put("data", result);
        return response;
    }

    @RequestMapping("global")
    public Map<String, Object> global() {
        Map<String, Object> result = new HashMap<>();
        result.put("currentDateTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        result.put("activeAmount", 20);

        Map<String, Object> response = new HashMap<>();

        response.put("data", result);
        return response;
    }
}
